//
//  actviityViewController.m
//  简单豆瓣不得不交版 1 带
//
//  Created by dllo on 16/6/23.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "actviityViewController.h"
#import "actviityTableViewCell.h"
#import "avtviityModel.h"
#import "TwoActvViewController.h"

static NSString *const cellActviity = @"CELL";

@interface actviityViewController ()<UITableViewDelegate, UITableViewDataSource>

@property(nonatomic, retain)UITableView *myTableView;
@property(nonatomic, retain)NSMutableArray *myArray;

@end

@implementation actviityViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.myArray = [NSMutableArray array];
    
    // Do any additional setup after loading the view.
    
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,0, 200, 44)];
    titleLabel.font = [UIFont boldSystemFontOfSize:20];
    titleLabel.textColor = [UIColor blackColor];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.text = @"活动";
    self.navigationItem.titleView = titleLabel;
   // self.navigationItem.title = @"活动";
    [self.navigationController.navigationBar setBarTintColor:[UIColor colorWithRed:0.3490 green:0.6118 blue:0.6706 alpha:1.000]];
    
    [self handleGata];
    [self creatTableView];
    
    
    
    
    
}

- (void)creatTableView {
    
    self.myTableView = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen]bounds] style:UITableViewStylePlain];
    self.myTableView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.myTableView];
    [_myTableView release];
    
    self.myTableView.delegate = self;
    self.myTableView.dataSource = self;
    
    [self.myTableView registerClass:[actviityTableViewCell class] forCellReuseIdentifier:cellActviity];
    
    
}

- (void)handleGata {
    
        NSString *path = [[NSBundle mainBundle] pathForResource:@"activitylist" ofType:@".txt"];
        NSData *data = [NSData dataWithContentsOfFile:path];
      NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
    
    NSArray *HXArray = [dic objectForKey:@"events"];
      for (NSDictionary *dic in HXArray) {
        avtviityModel *model = [[avtviityModel alloc] init];
        [model setValuesForKeysWithDictionary:dic];
        [self.myArray addObject:model];
        
        
    }

    
    
    
    
    
}




- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    actviityTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellActviity forIndexPath:indexPath];
    avtviityModel *model = [self.myArray objectAtIndex:indexPath.row];
    cell.model = model;
 
  //  取消uitableviewcell的点以效果
    cell.selectionStyle = UITableViewCellSelectionStyleNone;

    return cell;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.myArray.count;
}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 200;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
//    AllModel *model  = [self.myarray objectAtIndex:indexPath.row];
//    cell.MyModell = model;
     TwoActvViewController *twoVC = [[TwoActvViewController alloc] init];

    avtviityModel *model = [self.myArray objectAtIndex:indexPath.row];
    twoVC.model = model;
    
       [self.navigationController pushViewController:twoVC animated:YES];
    
    
    
}







- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
